package com.aaa.stock.service.Impl;

import com.aaa.entity.InventoryLog;
import com.aaa.entity.Medicines;
import com.aaa.entity.Producer;
import com.aaa.stock.dao.InventoryDao;
import com.aaa.stock.dao.MedicinalDao;
import com.aaa.stock.service.InventoryService;
import com.aaa.stock.vo.InventoryVo;
import com.aaa.stock.vo.Inventoryvo1;
import com.aaa.vo.Result;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Objects;

@Service
public class InventoryServiceImpl extends ServiceImpl<InventoryDao, InventoryLog> implements InventoryService {
    @Autowired
    private InventoryDao inventoryDao;
    @Autowired
    private  MedicinalDao medicinalDao;
    @Override
    public Result<IPage<Medicines>> findByall(Integer currentPage, Integer pageSize, InventoryVo inventoryVo) {
        IPage<Medicines> page=new Page<>(currentPage,pageSize);
        QueryWrapper<Medicines> wrapper=new QueryWrapper<>();
        if (StringUtils.hasText(inventoryVo.getMedicinesName())){
            wrapper.like("medicines_name",inventoryVo.getMedicinesName());
        }
        if (StringUtils.hasText(inventoryVo.getKeywords())){
            wrapper.like("keywords",inventoryVo.getKeywords());
        }
        if (StringUtils.hasText(inventoryVo.getMedicinesType())){
            wrapper.eq("medicines_type",inventoryVo.getMedicinesType());
        }
        if (StringUtils.hasText(inventoryVo.getPrescriptionType())){
            wrapper.eq("prescription_type",inventoryVo.getPrescriptionType());
        }
        if (StringUtils.hasText(inventoryVo.getProducterId())){
            wrapper.eq("producter_id",inventoryVo.getProducterId());
        }
        if (Objects.nonNull(inventoryVo.getDateRange()) && inventoryVo.getDateRange().length==2){
            wrapper.between("create_time",inventoryVo.getDateRange()[0],inventoryVo.getDateRange()[1]);
        }

        IPage<Medicines> page1 = medicinalDao.selectPage(page, wrapper);
        return new Result<IPage<Medicines>>(200,"查询用户成功",page1);    }

    @Override
    public Result<IPage<InventoryLog>> findByall1(Integer currentPage, Integer pageSize, Inventoryvo1 inventoryVo1) {
        IPage<InventoryLog> page=new Page<>(currentPage,pageSize);
        QueryWrapper<InventoryLog> wrapper=new QueryWrapper<>();
        if (StringUtils.hasText(inventoryVo1.getPurchaseId())){
            wrapper.like("purchase_id",inventoryVo1.getPurchaseId());
        }
        if (StringUtils.hasText(inventoryVo1.getMedicinesName())){
            wrapper.like("medicines_name",inventoryVo1.getMedicinesName());
        }
        if (StringUtils.hasText(inventoryVo1.getMedicinesType())){
            wrapper.eq("medicines_type",inventoryVo1.getMedicinesType());
        }

        if (StringUtils.hasText(inventoryVo1.getProducterId())){
            wrapper.eq("producter_id",inventoryVo1.getProducterId());
        }
        if (StringUtils.hasText(inventoryVo1.getPrescriptionType())){
            wrapper.eq("prescription_type",inventoryVo1.getPrescriptionType());
        }
        if (Objects.nonNull(inventoryVo1.getDateRange()) && inventoryVo1.getDateRange().length==2){
            wrapper.between("create_time",inventoryVo1.getDateRange()[0],inventoryVo1.getDateRange()[1]);
        }


        IPage<InventoryLog> page1 = inventoryDao.selectPage(page, wrapper);
        return new Result<IPage<InventoryLog>>(200,"查询用户成功",page1);
    }
}
